﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_FlowForm.cshtml";
}

<script>
    var keyValue = request('keyValue');
    var parentId = "0";
    var ParentSort = 0;
    $(function () {
        initControl();
    })
    //初始化控件
    function initControl() {
        //上级
        $("#ParentIdTree").ComboBoxTree({
            url: "../../ResourceManage/RS_DeviceType/GetTreeJson",
            description: "==请选择==",
            height: "230px",
            click: function (item) {
                
                if (item.id != parentId) {
                    parentId = item.id;
                    ParentSort = parseInt(item.Sort);
                    $("#Sort").val(ParentSort + 1);
                }
            }
        });
        //获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "../../ResourceManage/RS_DeviceType/GetFormJson",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data);
                    $("#ParentIdTree").ComboBoxSetValue(data.ParentId);
                    parentId = data.ParentId;
                }
            });
        }
    }
    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        if (!parentId) { parentId = "0" }
        postData["ParentId"] = parentId;
        postData["Sort"] = ParentSort + 1;
        $.SaveForm({
            url: "../../ResourceManage/RS_DeviceType/SaveForm?keyValue=" + keyValue,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        })
    }

</script>
<div style="margin-top: 20px; margin-right: 30px;">
    <input id="ParentId" type="hidden" />
    <table class="form">
        <tr>
            <th class="formTitle">上级</th>
            <td class="formValue">
                <div id="ParentIdTree" type="selectTree" class="ui-select"></div>
            </td>
        </tr>
        <tr>
            <td class="formTitle">种类名称<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="Name" type="text" onblur="$.ExistField(this.id, '../../ResourceManage/RS_DeviceType/ExistName')" class="form-control" placeholder="请输入种类名称" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">种类编号<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="Code" type="text" onblur="$.ExistField(this.id, '../../ResourceManage/RS_DeviceType/ExistCode')" class="form-control" placeholder="请输入种类编号" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">级别<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="Sort" type="text" readonly="readonly" class="form-control" value="1" isvalid="yes" checkexpession="Num" />
            </td>
        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;">
                备注
            </th>
            <td class="formValue">
                <textarea id="Description" class="form-control" style="height: 70px;"></textarea>
            </td>
        </tr>
    </table>
</div>
